package com.jv.exception;

import com.jv.entity.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常，返回的json数据前端也可以捕获(放入提示框等)
 * @author Jv
 * @version 1.0
 */
@ControllerAdvice
@ResponseBody
public class GlobleExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public R exceptionHandle(HttpServletRequest request,Exception e){
        System.out.println("全局异常");
        return R.error("服务器端异常,请联系管理员"+"<br/>"+e.getMessage());
    }
}
